package com.atguigu.eduservice.controller.front;

import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/frontTeacher")
@CrossOrigin
public class FrontTeacherController {
    @Resource
    EduTeacherService eduTeacherService;
    @Autowired
    EduCourseService eduCourseService;
    // 分页查询讲师
    @PostMapping("/getAllteacher/{page}/{limit}")
    public R getAllteacher(@PathVariable long page,@PathVariable long limit){
        Page<EduTeacher> pageParam = new Page<EduTeacher>(page, limit);

        Map<String, Object> map = eduTeacherService.pageListWeb(pageParam);
        return R.ok().data(map);
    }
    // 根据id查询讲师详情和课程信息
    @GetMapping("/detail/{id}")
    public R getTeacherDetail(@PathVariable String id){
        EduTeacher teacherDetail = eduTeacherService.getById(id);
        QueryWrapper<EduCourse> courseQueryWrapper = new QueryWrapper<>();
        courseQueryWrapper.eq("teacher_id",id);
        List<EduCourse> list = eduCourseService.list(courseQueryWrapper);
        return R.ok().data("teacherDetail",teacherDetail).data("courses",list);

    }
}
